package com.bolt.admin.web.view.jsp;

import com.bolt.admin.module.sys.service.MenuService;
import com.bolt.common.utils.SpringContextUtil;
import com.bolt.support.ui.tree.vo.UITreeNode;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.List;

/**
 * 首页菜单数据
 * Created by Administrator on 2018/1/29.
 */
public class AuthMenuTag extends TagSupport {
    private String id;

    @Override
    public int doStartTag() throws JspException {
        if (this.id == null) {
            throw new JspException("tag id not be null");
        }
        MenuService menuService = SpringContextUtil.getBean(MenuService.class);
        if (menuService == null) {
            throw new JspException("Could not obtain the menu Service");
        }


        List <UITreeNode> nodes = menuService.authUserMenu();
        pageContext.setAttribute(this.id, nodes);

        return (EVAL_BODY_INCLUDE);
    }

    @Override
    public int doEndTag() throws JspException {
        //pageContext.removeAttribute(this.id);
        return EVAL_BODY_INCLUDE;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }
}
